/*
  ID: nemokin1
  PROG: agrinet
  LANG: C++
*/
#include <vector>
#include <list>
#include <assert.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <fstream>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
 
using namespace std;
 
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=b;--i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define ALL(c) (c).begin(),(c).end()
 
#define debug(x) cerr<< #x << " = " << (x) << "\n";
#define debugv(v) cerr << #v << " = "; FOREACH(it,v) cerr << *it <<","; cerr << "\n";
#define SIZE(a)  (int(a.size()))
#define mp make_pair
#define pb push_back
 
template<typename T> inline void checkMax(T& a, T b) {if (b>a) a=b;}
template<typename T> inline void checkMin(T& a, T b) {if (b<a) a=b;}
 
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int>  ii;
typedef long double ld;
const int INF = 1000000000;
int adj[101][101];
int rank[101];
int pi[101];

int find(int x)
{
    if(x == pi[x]) return x;
    return find(pi[x]);
}

void unite(int x, int y)
{
    if(rank[x] > rank[y]){
	pi[y] = x;
    }
    else{
	pi[x] = y;
	if(rank[x] == rank[y]) rank[y]++;
    }
}

int main(){
    freopen("agrinet.in","r",stdin);freopen("agrinet.out","w",stdout);
    int N;
    cin >> N;
    REP(i,N) REP(j,N){
	int q;
	cin >> q;
	adj[i][j] = q;
    }
    vector<pair<int, pair<int,int> > > vp;    
    for(int i = 0; i < N; i++){
	for(int j = i+1; j < N; j++){
	    vp.pb(mp(adj[i][j],mp(i,j)));
	}
    }
    sort(vp.begin(),vp.end());
    REP(i,N) pi[i] = i;
    
    int ret = 0;
    
    for(int i = 0; i < SIZE(vp); i++){
	int rx = find(vp[i].second.first);
	int ry = find(vp[i].second.second);
	if(rx != ry){
	    ret+=vp[i].first;
	    unite(rx,ry);
	}
    }
    cout << ret << endl;
    return 0;
}

		
    

    

